package com.work.yshop.model;

import java.io.Serializable;

/**
 * 购物车项模型类
 */
public class CartItem implements Serializable {
    private int id;
    private int productId;
    private int userId;
    private int quantity;
    private boolean selected;
    private long addTime;
    private Product product; // 关联的商品对象

    public CartItem() {
        this.selected = true; // 默认选中
    }

    public CartItem(int productId, int userId, int quantity) {
        this.productId = productId;
        this.userId = userId;
        this.quantity = quantity;
        this.selected = true;
        this.addTime = System.currentTimeMillis();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getProductId() {
        return productId;
    }

    public void setProductId(int productId) {
        this.productId = productId;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }

    public long getAddTime() {
        return addTime;
    }

    public void setAddTime(long addTime) {
        this.addTime = addTime;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }
    
    /**
     * 计算小计金额
     */
    public double getSubtotal() {
        return product != null ? product.getPrice() * quantity : 0;
    }
} 